﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using Stala;

namespace TestApp
{
	class DownloadVersionCommand : ICommand
	{
		private IVersionDownloader versionDownloader;
		public IVersionDownloader VersionDownloader
		{
			get { return versionDownloader; }
			set
			{
				versionDownloader = value;
				CanExecuteChanged(this, null);
			}
		}

		public bool CanExecute(object parameter)
		{
			if (VersionDownloader == null)
				return false;
			return true;
		}

		public event EventHandler CanExecuteChanged;

		public void Execute(object parameter)
		{
			try
			{
				versionDownloader.Download();
			}
			catch (Exception ex)
			{
				if (DownloadFailed != null)
					DownloadFailed(ex);
			}
		}

		public event Action<Exception> DownloadFailed;
	}
}
